﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;

public partial class AjaxXml_AjaxUserCheck : BasePage
{
    protected string Un = "";
    protected string Pwd = "";
    protected string CheckCode = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        bool isLogin = true;
        int Result = -1;//错误
        string Msg = "";
        try
        {
            if (Request["Pwd"] != null)
            {
                Pwd = Request["Pwd"];
            }
            if (Request["Un"] != null)
            {
                Un = Request["Un"];
            }
            if (Request["Code"] != null)
            {
                CheckCode = Request["Code"];
            }
            if (Un == "")
            {
                Msg = "用户名不能为空";
                isLogin = false;
            }
            if (Pwd == "")
            {
                Msg = "密码不能为空";
                isLogin = false;
            }
            if (CheckCode == "")
            {
                Msg = "验证码不能为空";
                Result = -2;
                isLogin = false;
            }
            else
            {
                if (Session["CheckCode"] != null)
                {
                    if (Session["CheckCode"].ToString().ToLower() != CheckCode)
                    {
                        Msg = "验证码输入错误!";// + Session["CheckCode"].ToString();
                        Result = -2;
                        isLogin = false;
                    }
                }
                else
                {
                    Msg = "验证码输入错误!";
                    Result = -2;
                    isLogin = false;
                }

            }
            if (isLogin)
            {
                Result = User_Bll.CreateNew.UserLogin(Un, EncryptString.md5(Pwd), 0, configInfo.DayAddIntegral, out Msg);

                if (Result >= 1)
                {
                    Msg = configInfo.InstallDir + "default.aspx";
                }
            }

        }
        catch
        {
            Result = -1;
        }
        Response.Write("{result:\"" + Result + "\",msg:\"" + Msg + "\"}");
    }
}
